package com.edgar.designpattern.proxy.order;

import java.util.ArrayList;
import java.util.List;

public class OrderImpl implements Order {
    
    private List items = new ArrayList();
    private String customerId;

    public OrderImpl(String customerId) {
        super();
        this.customerId = customerId;
    }

    @Override
    public String getCustomerId() {
        return customerId;
    }

    @Override
    public void addItem(Product p, int quantity) {
        Item item = new Item(p, quantity);
        items.add(item);
    }

    @Override
    public int total() throws Exception {
        int total = 0;
        for (int i = 0; i < items.size(); i ++) {
            Item item = (Item) items.get(i);
            Product p = item.getProduct();
            int qty = item.getQuantity();
            total += p.getPrice() * qty;
        }
        return total;
    }

}
